﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HaveARest
{
    public partial class RestSetting : Form
    {
        public RestSetting(RestInfo restInfo)
        {
            InitializeComponent();
            info = restInfo;
        }

        public RestSetting()
        {
            InitializeComponent();
        }

        public void SetData()
        {
            this.nudMaxBusyTime.Value = info.maxBusyTime;
            this.nudMaxInterval.Value = info.busySpan;
        }

        private void btnSetDefault_Click(object sender, EventArgs e)
        {
            this.nudMaxBusyTime.Value = info.defaulMaxBusyTime;
            this.nudMaxInterval.Value = info.defaulBusySpan;
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            info.maxBusyTime = (int)this.nudMaxBusyTime.Value;
            info.busySpan = (int)this.nudMaxInterval.Value;
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            //do nothing
            this.DialogResult = DialogResult.Cancel;
        }

        private void cbEnableRest_CheckedChanged(object sender, EventArgs e)
        {
            if (this.cbEnableRest.Checked)
            {
                this.nudMaxBusyTime.Enabled = true;
                this.nudMaxInterval.Enabled = true;
                info.enabled = true;
            } 
            else
            {
                this.nudMaxBusyTime.Enabled = false;
                this.nudMaxInterval.Enabled = false;
                info.enabled = false;
            }
        }

        RestInfo info;
    }
}